//测试CubeMap的像素着色器

//顶点着色器输出
struct VS_OUTPUT
{
    float4 Pos : SV_POSITION;
    float3 Normal : NORMAL;
	float3 Tangent : TANGENT;
	float2 TexCoord : TEXCOORD0;
	float3 WorldPosition : TEXCOORD1;
};

Texture2D ourTexture : register( t9 );
SamplerState ourSampler : register( s5 );

cbuffer SceneData : register( b7 )
{
	matrix View;
	matrix Projection;
	float4 lightDir;
	float4 eyePosition;
}

float4 Main( VS_OUTPUT input ) : SV_Target
{
	//光线方向
	float3 LightDir = lightDir.xyz;
	
	//计算法线方向：
	float3 NormalDir = float3(0,0,1);
	{
		//切线空间的法线
		float4 TangentNormal = ourTexture.Sample( ourSampler, input.TexCoord );
		TangentNormal = TangentNormal * 2 - float4(1, 1, 1, 1);
	
		//切线空间三轴在模型空间的基向量：
		float3 BaseN = normalize(input.Normal);
		float3 BaseT = normalize(input.Tangent);
		float3 BaseB = cross(BaseT,BaseN);
		
		//模型空间的法线方向：
		NormalDir = BaseT*TangentNormal.x + BaseB*TangentNormal.y + BaseN*TangentNormal.z;
	}
	
	//光线点乘法线
	float NdL = dot(normalize(NormalDir),normalize(LightDir));
	
	//将NdL限定在0到1
	NdL = saturate(NdL);
	
	//颜色系数
	float c = NdL * 0.7 + 0.3;

	return float4( c, c, c, 1.0 );
}
